<?php

namespace app\index\controller;

use app\index\model\User as UserModel;
use app\index\model\Data;
use app\index\model\Profile;
use think\Loader;
use think\Controller;

class User extends Controller
{
	public function show()
	{
		$this->assign('title','这里是默认标题');
		$this->assign('content','终于见到你');
		return $this->fetch();
	}
	public function login()
	{
		$this->assign('title','这里是默认标题');
		$this->assign('content','终于见到你');
		return $this->fetch();
	}
	public function register()
	{
		$this->assign('title','这里是默认标题');
		$this->assign('content','终于见到你');
		return $this->fetch();
	}
/*
	public function oneToMany()
	{
		$user = UserModel::get(3);
		dump($user->artical);
	}


	public function oneToOne()
	{
		$user = UserModel::get(2);
		echo $user->profile()->save(
			['age'=>10,
			'sex'=>0,
			'wechat'=>'ad1dd']);
		$p = profile::get(1);
		echo $p->user->nickname;
	}


	public function auto(UserModel $user)
	{
		$user->save();
	}
	public function softDelete()
	{
		//$nihao = UserModel::get(6);
		//$nihao->delete(true);
		dump(UserModel::onlyTrashed()->find());
	}


	}
	public function autoTime(UserModel $user)
	{
		//$user->nickname = 'nihao';
		//$user->save();
		$u = $user->get(5);
		$u->save(['nickname'=>'你想干嘛']);
	}

	public function getter(){
		$u = Data::get(1);
		echo $u->getData('status');
		//$u->name = 'ABHello';
		//$u->save();
	}*/
	//测试模型
	public function model()
	{
		//静态调用
		/*
		$u = UserModel::get(1);
		$u->nickname = 'tom';
		$u->save();

		//实例化模型
		$u = new UserModel();
		$u->nickname = 'xiaohong';
		$u->save();

		$u = Loader::model('User');
		$u->nickname = 'huahua';
		$u->save();

		$u = model('User');
		$u->nickname = 'jingjing';
		$u->save();

		$u = model('User');
		$u->data(['nickname' => 'zhaoliying','email'=>'zly@xx.com']);
		$u->save();
		dump($u->id);

		$u = model('User');
		$u->nickname = 'abc';
		$u->save();
		$u->nickname = 'hello';
		$u->save();
		*/
		$u = UserModel::create(['nickname'=>'qiange']);
		dump($u->nickname);
	}

	public function index()
	{
		return '调用了user控制器的index方法';
	}
}